<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Zhou Wenying
  Date: 2023/2/6
  Time: 22:41
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>旧书交易平台</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/login.css">

</head>

<body id="login">

<div class="login">
    <h2> <strong><font face="仿宋" >旧书交易平台注册</font></strong></h2>
    <c:if test="${requestScope.msg != null}">
        <h3 style="color: red"><c:out value="${requestScope.msg}"></c:out></h3>
    </c:if>

    <form  method="post" action="/doRegister">

        <div class="layui-form-item">
            <input value="${requestScope.saveUser.getUserName()}" type="text" name="username"  id="username" placeholder="账号" class="layui-input" required>
            <i class="layui-icon input-icon">&#xe66f;</i>
        </div>

        <div class="layui-form-item">
            <input value="${requestScope.saveUser.getUserNickname()}" type="text" name="nickname"  id="nickname" placeholder="昵称" class="layui-input" required>
            <i class="layui-icon input-icon">&#xe66f;</i>
        </div>

        <div class="layui-form-item">
            <input  type="password" name="password" id="password" placeholder="密码"  class="layui-input" required>
            <i class="layui-icon input-icon">&#xe673;</i>
        </div>

        <div class="layui-form-item">
            <input type="text" name="repassword"  id="repassword" placeholder="确认密码" class="layui-input" required>
            <i class="layui-icon input-icon">&#xe673;</i>
        </div>

        <div class="layui-form-item">
            <input value="${requestScope.saveUser.getUserEmail()}" type="text" name="email"  id="email" placeholder="邮箱" lay-verify="email" class="layui-input" required>
            <i class="layui-icon input-icon">&#xe618;</i>
<%--            <i class="layui-icon layui-icon-email">&#xe618;</i>--%>
        </div>

        <div class="layui-form-item">
            <%--<div class="layui-input-block">--%>
                <div class="layui-row">
                    <div class="layui-col-md6">
                        <input value="${requestScope.emscode}" type="text" name="emscode"  id="emscode" placeholder="邮箱验证码" class="layui-input" required>
                        <i class="layui-icon input-icon">&#xe679;</i>
                    </div>
                    <div class="layui-col-md2">
                        <input type="button" id="getCode" value="获取验证码"  class="layui-btn"></input>
                    </div>
                </div>
                <%--<button style="width: 100%" class="layui-btn layui-btn-radius layui-btn-normal" lay-submit lay-filter="login" >立即注册</button>--%>
        </div>

        <div class="layui-form-item">
            <button style="width: 100%" class="layui-btn layui-btn-radius layui-btn-normal" lay-submit lay-filter="register" >立即注册</button>
        </div>

        <br>

        <div>
            <a style="font-family: 仿宋;color: #666666" href="/login">已有账号？<span style="color: #225592">去登录</span></a>
        </div>
    </form>

</div>

</body>

</html>

<script src="/static/js/jquery-3.6.1.min.js"></script>
<script src="/static/layui/layui.js"></script>
<script src="/static/layer/layer.js"></script>
<script>

    $("#getCode").click(function () {
        //json对象格式化为json字符串
        //var ss = JSON.stringify(obj);
        //json字符串解析为json对象
        //var p = JSON.parse(ss);

        var username = $("#username").val();
        var toMail = $("#email").val();

        var obj = {};
        obj.username = username;
        obj.toMail = toMail;

        var json = JSON.stringify(obj);
        console.log(json);

        $.ajax({
            url:"/getEMSCode",
            type:"post",
            dataType:"json",
            data:json,
            contentType: false,
            success:function (data) {
                console.log(data);
                //var obj = JSON.parse(data);
                if (data.ret == 'true'){
                    console.log("true 111");
                    layer.msg('获取验证码成功！');
                }else {
                    alert(data.data);
                }
            },
            error:function (data) {

            }
        });

    })
</script>

